import { Injectable, NotFoundException } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { CreateAdminDto } from './dto/create-admin.dto';
import { Admin } from './entities/admin.entity';

@Injectable()
export class AdminService {
  constructor(
    @InjectRepository(Admin)
    private readonly adminRepository: Repository<Admin>,
  ) {}

  async findOne(admin: CreateAdminDto) {
    const result = await this.adminRepository.find({
      where: { userName: admin.userName, password: admin.password },
    });
    if (result.length > 0) {
      return { token: '0A885265A1BA1504107B9D63CD834059' };
    } else {
      throw NotFoundException;
    }
  }
}
